import { IProject } from 'screens/project-list/list'
import { useAsync } from './use-async'
import { clearEmptyKey } from 'utils'
import { useCallback, useEffect } from 'react'
import { useHttp } from 'utils/http'
export const useProjects = (param?: Partial<IProject>) => {
  const { run, ...result } = useAsync<IProject[]>()
  const client = useHttp()
  const fetchProhects = useCallback(() => client('projects', { data: clearEmptyKey(param || {}) }), [param, client])
  // 当param发生变化时,请求数据
  useEffect(() => {
    run(fetchProhects(), {
      retry: fetchProhects
    })
  }, [param, run, fetchProhects])

  return result
}
